﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;

namespace War3GameBroadcaster
{
    public class ListBoxTraceListener : TraceListener
    {
        private ListBox list = null;

        public ListBoxTraceListener(ListBox list)
        {
            this.list = list;
        }

        public override void WriteLine(string s)
        {
            if (list != null)
            {
                if (list.InvokeRequired)
                {
                    list.Invoke(new AddLineDelegate(AddLine), s);
                }
                else
                {
                    AddLine(s);
                }
            }
        }
        delegate void AddLineDelegate(string line);
        void AddLine(string line)
        {
            list.Items.Add(line);
        }

        public override void Write(string s)
        {
            WriteLine(s);
        }
    }
}
